<?php
class Component_introslide_register extends appRain_Base_Component
{
    public function init()
    {
        App::Module('Hook')->setHookName('UI')
                           ->setAction("home_page_banner")
                           ->Register(get_class($this),"add_html");

		App::Module('Hook')->setHookName('UI')
                           ->setAction("introside_steps_slider")
                           ->Register(get_class($this),"steps_slider_html");

		App::Module('Hook')->setHookName('CSS')
                           ->setAction("register_css_code")
                           ->Register(get_class($this),"register_css_code");

        App::Module('Hook')->setHookName('Javascript')
                           ->setAction("register_javascript_code")
                           ->Register(get_class($this),"register_javascript_code");



		App::Module('Hook')->setHookName('InterfaceBuilder')
                           ->setAction("update_definition")
                           ->Register(get_class($this),"interfacebuilder_update_definition");

		App::Module('Hook')->setHookName('InformationSet')
                           ->setAction("register_definition")
                           ->Register(get_class($this),"register_informationset_defination");


    }

    public function init_on_install(){}

    public function init_on_uninstall(){}

	public function add_html($send)
    {
         App::setUserStatusId(0);
		$imageData = App::InformationSet('introslideimg')->findAll("1 ORDER BY RAND()",Array(Array("status"=>"Active")));
		return App::Helper('Utility')->callElementByPath($this->attachMyPath('elements/slider.phtml'),array('imageData'=>$imageData));
    }

	public function steps_slider_html($send)
    {
         App::setUserStatusId(0);
		$imageData = App::InformationSet('introslidesteps')->findAll("1 ORDER BY ID ASC",Array(Array("status"=>"Active")));
		return App::Helper('Utility')->callElementByPath($this->attachMyPath('elements/stepslider.phtml'),array('imageData'=>$imageData));
    }

    public function register_css_code()
    {
        return App::Helper('Utility')->fetchFile($this->attachMyPath('css/styles.css'));
    }

    public function register_javascript_code()
    {
        return App::Helper('Utility')->fetchFile($this->attachMyPath('js/loopedslider.js')) . "\n" .
			   App::Helper('Utility')->fetchFile($this->attachMyPath('js/looped-options.js'))	;
    }

	public function interfacebuilder_update_definition($send)
    {
        if(isset($send['component']['child']))
        {
            $send['component']['child'][] = Array("title"=>"Intro Slide",
												"items"=>Array(array("title"=>"New Slide","link"=>"/information/manage/introslideimg/add"),
															   array("title"=>"Manage Slides","link"=>"/information/manage/introslideimg"),
															   array("title"=>"New Step","link"=>"/information/manage/introslidesteps/add"),
															   array("title"=>"Manage Steps","link"=>"/information/manage/introslidesteps")),
                                                "adminicon" => array("type"=>"filePath",'location'=>'/component/appbanners/icon/bannermanager.jpg'));
            return $send;
        }
    }

	public function register_informationset_defination()
    {
        $srcpaths = Array();
        $srcpaths[] =   array('type'=>'introslideimg',
                               'path'=>$this->attachMyPath('information_set/introslideimg.xml'));
		$srcpaths[] =   array('type'=>'introslidesteps',
                               'path'=>$this->attachMyPath('information_set/introslidesteps.xml'));
        return $srcpaths;
    }
}